package com.ljf.framework.Async;

import com.ljf.framework.context.LjfContext;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 说明：
 *
 * @Auther: lijinfeng
 * @Date: 2024/8/1
 */
public class AsyncServiceDefaultImpl extends AsyncAbstractService{

    @Override
    public  <T> AsyncResult<T> supplyAsyncCus(AsyncEvent<T> asyncEvent, ThreadPoolExecutor threadPoolExecutor){
        // 创建一个CompletableFuture实例
        CompletableFuture<T> futurePrice = CompletableFuture.supplyAsync(asyncEvent::runPrepare, threadPoolExecutor);
        // 当结果准备好后，获取它
        return new AsyncResult<>(futurePrice);
    }

    @Override
    public void runAsyncCus(AsyncEvent asyncEvent, ThreadPoolExecutor threadPoolExecutor) {
        CompletableFuture.runAsync(asyncEvent::runPrepare,threadPoolExecutor);
    }
}
